package com.atwisdom.star.common.util;

import cn.hutool.core.util.StrUtil;
import com.atwisdom.star.common.enums.FirstTypeEnum;

/**
 * 
 * @Date: 2023-04-04 14:29
 * 将key包装为如下形式"model:entity:className:material:comment 'comment'"
 */
public class RedisKeyUtil {

    public static final String delimiter = ":";

    /**
     * 获取Key
     * @param firstType
     * @param objectType
     * @param identifyKey
     * @param identifyValue
     * @param field
     * @return
     */
    public static String getKey(FirstTypeEnum firstType, String objectType, String identifyKey, String identifyValue, String field) {
        String tempStr = String.join(delimiter, firstType.getCode(), objectType, identifyKey, identifyValue);
        return StrUtil.isBlank(field) ? tempStr : String.join(delimiter, tempStr, field);
    }

    /**
     * 根据objectType获取key
     * @param firstType
     * @param objectType
     * @return
     */
    public static String getKey(FirstTypeEnum firstType, String objectType) {
        return String.join(delimiter, firstType.getCode(), objectType);
    }

    /**
     * 根据objectType获取key
     * @param firstType
     * @param objectType
     * @return
     */
    public static String getKey(FirstTypeEnum firstType, Long objectType) {
        return String.join(delimiter, firstType.getCode(), String.valueOf(objectType));
    }

}